package com.zzy.controller;

import com.zzy.model.AppInfo;
import com.zzy.model.VersionInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/app")
public class AppController {

    @GetMapping("/list")
    public String list(Model appInfoMap) {
        List<AppInfo> appInfoList = new ArrayList<>();
        AppInfo appInfo = new AppInfo();
        appInfo.setId(3323l);
        appInfo.setAppName("微信");
        appInfo.setIcon("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3243742975,3971594754&fm=26&gp=0.jpg");
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoList.add(appInfo);
        appInfoMap.addAttribute("appList", appInfoList);
        return "/app/list";
    }

    @GetMapping("/detail/{id}")
    public String appInfo(@PathVariable Long id, Model model) {
        List<VersionInfo> appInfoList = new ArrayList<>();
        VersionInfo vi = new VersionInfo();
        vi.setStatus(1);
        vi.setVersionName("1.8.9");
        vi.createDate = new Date();
        appInfoList.add(vi);

        vi = new VersionInfo();
        vi.setStatus(0);
        vi.setVersionName("1.8.8");
        vi.createDate = new Date();
        appInfoList.add(vi);

        vi = new VersionInfo();
        vi.setStatus(0);
        vi.setVersionName("1.8.7");
        vi.createDate = new Date();
        appInfoList.add(vi);
        model.addAttribute("list", appInfoList);

        AppInfo appInfo = new AppInfo();
        appInfo.setId(3323l);
        appInfo.setAppName("微信");
        appInfo.setIcon("https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3243742975,3971594754&fm=26&gp=0.jpg");
        model.addAttribute("app", appInfo);
        return "/app/info";
    }
}
